<?php

namespace app\admin\model;

use think\Db;
use think\Model;
use think\session;
class Core extends Model
{
    // 表名
    protected $name = 'core';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;
    protected $insert = ['user'];

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;

    // 追加属性
    protected $append = [
        'inputtime_text',
        'week_text'
    ];

    protected function setUserAttr()
    {
        $a = Session::get('admin');
        return $a['username'];

    }
    public function getWeekTextAttr($value,$data){
        $a= intval(date("W",strtotime($data['starttime'])));
        return "第".$a.'周  '.$data['starttime'];

    }
    function  getDepartmentAttr($value){
       $data =  Db::name('auth_department')->field('name')->where('id',$value)->find();
       return $data['name'];
    }
    function  getInputtimeAttr($value)
    {
        return date("Y-m-d H:i:s",$value);
    }

    public function getInputtimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['inputtime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setInputtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
